package me.huangxiang.design_pattern.composite;

import java.util.ArrayList;
import java.util.List;

public class Folder extends AbstractFile {
    private String name;

    public Folder(String name) {
        this.name = name;
    }

    private List<AbstractFile> list = new ArrayList<>();

    @Override
    public void add(AbstractFile c) {
        this.list.add(c);
    }

    @Override
    public void remove(AbstractFile c) {
        this.list.remove(c);
    }

    @Override
    public AbstractFile getChild(int i) {
        return this.list.get(i);
    }

    @Override
    public void killVirus() {
        System.out.println("-----对文件夹" + name + "进行杀毒！");
        for (AbstractFile c : this.list){
            c.killVirus();
        }
    }
}
